#include "common_monitor.h"
#include "board_includes.h"
/* private define -------------------------------------------------------- */
#define	USER_TIMER_MAX			32

typedef struct
{
	const char *name;
    void (*func)(void *priv);
    u32 interval_ms;
}UserTimerInfo_t;
/* private function prototypes ---------------------------------------------- */
static void common_monitor_1s_poll(void);
static void common_monitor_500ms_poll(void);
static void common_monitor_5s_poll(void);
static void common_monitor_10ms_poll(void);


/* private variables -------------------------------------------------------- */

static uint16_t g_timer_hdl[USER_TIMER_MAX] = {0};
static const UserTimerInfo_t UserTimer[USER_TIMER_MAX] =
{
	{"10ms poll", 	common_monitor_10ms_poll		, 10},
	{"500ms poll", 	common_monitor_500ms_poll		, 500},
	{"1s poll", 	common_monitor_1s_poll			, 1000},
	{"5s poll", 	common_monitor_5s_poll			, 5000},
	{"event poll", 	ej_event_process				, 10},


};

/* private functions -------------------------------------------------------- */
static void common_monitor_1s_poll(void)
{

}

static void common_monitor_500ms_poll(void)
{

}

static void common_monitor_5s_poll(void)
{
#if LIB_DEBUG
	mem_stats();printf("\n");

	//os_system_info_output();printf("\n");
#endif
}

static void common_monitor_10ms_poll(void)
{

}

/* public functions -------------------------------------------------------- */

void common_monitor_init(void)
{
	memset(g_timer_hdl, 0, sizeof(g_timer_hdl));

	for (int i = 0; i < USER_TIMER_MAX; i++)
	{
		if ((!UserTimer[i].func) || (UserTimer[i].interval_ms == 0))
		{
			continue;
		}

		g_timer_hdl[i] = sys_timer_add(NULL, UserTimer[i].func, UserTimer[i].interval_ms);
	}

}

void common_monitor_exit(void)
{
	for (int i = 0; i < USER_TIMER_MAX; i++)
	{
		if (g_timer_hdl[i])
		{
			sys_timer_del(g_timer_hdl[i]);
		}
	}

	memset(g_timer_hdl, 0, sizeof(g_timer_hdl));
}
